import React, { Component } from 'react'
import { withRouter } from 'react-router-dom'
import { connect } from 'react-redux'

class Detail extends Component {
    render() {
        console.log(this.props)
        const { addItem } = this.props
        return (
            <div>
                我是详情页
                <div>
                    <button onClick = {() => {
                        addItem(this.props.location.state.item)
                    }}>添加</button>
                </div>
            </div>
        )
    }
}

const mapStateToProps = (state) => ({
    
})


const mapDispatchToProps = (dispatch) => {
    return {
        addItem(item) {
            dispatch({ type: "ADD_ITEM", item })
        }
    }
}


export default withRouter(connect(mapStateToProps, mapDispatchToProps)(Detail))
